package com.hydl.power.controller;

import com.github.pagehelper.PageInfo;
import com.hydl.power.aop.annotation.LogAnnotation;
import com.hydl.power.pojo.AlarmSet;
import com.hydl.power.pojo.Device;
import com.hydl.power.service.AlarmSetService;
import com.hydl.power.service.DeviceService;
import com.hydl.power.utils.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wxb
 * @date 2020/4/17 18:25
 */
@Api(value = "AlarmSetController",tags = "事件记录/告警设置")
@RequestMapping("/alarmSet")
@RestController
@CrossOrigin
public class AlarmSetController {
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private AlarmSetService alarmSetService;

    //@LogAnnotation(module = "事件记录/告警设置",description = "查询告警设置")
    @ApiOperation("查询告警设置")
    @PostMapping("/getAdvancedSetup")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数",  dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "条数", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "areaId", value = "区域id",defaultValue = "78371788", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "navId", value = "单位项目ID",defaultValue = "50642475", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "powerRoomId", value = "配电房id",defaultValue = "35053285", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "43087293", dataType = "String"),
    })
    public Resp<PageInfo<Device>> getAdvancedSetup(Integer pageNum, Integer pageSize, String areaId, String navId, String powerRoomId, String deviceId){
        PageInfo<Device> pageInfo = deviceService.getAllDeviceById(pageNum, pageSize, areaId, navId, powerRoomId, deviceId);
        return Resp.success(pageInfo);
    }

    //@LogAnnotation(module = "事件记录/告警设置",description = "根据设备deviceId获取告警设置数据")
    @ApiOperation("根据设备deviceId获取告警设置数据")
    @PostMapping("/selectBydeviceId")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "40371336", dataType = "String"),
    })
    public Resp<AlarmSet> selectBydeviceId(String deviceId){
        AlarmSet alarmSet = alarmSetService.selectBydeviceId(deviceId);
        return Resp.success(alarmSet);
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "修改线电压Uab")
    @ApiOperation("修改线电压Uab")
    @PostMapping("/updateAlarmSetUab")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "uabClass", value = "线电压uab 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "uabBeginValue", value = "线电压uab 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "uabEndValue", value = "线电压uab 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "uabFlag", value = "线电压uab 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetUab(String deviceId,Integer uabClass,String uabBeginValue,String uabEndValue,Integer uabFlag){
        int i = alarmSetService.updateAlarmSetUab(deviceId, uabClass, uabBeginValue, uabEndValue, uabFlag);
        if (i==1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }

    @LogAnnotation(module = "事件记录/告警设置",description = "修改线电压Ubc")
    @ApiOperation("修改线电压Ubc")
    @PostMapping("/updateAlarmSetUbc")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "ubcClass", value = "线电压Ubc 1 一般 2严重 3紧急",dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "ubcBeginValue", value = "线电压Ubc 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "ubcEndValue", value = "线电压Ubc 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "ubcFlag", value = "线电压Ubc 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetUbc(String deviceId,Integer ubcClass,String ubcBeginValue,String ubcEndValue,Integer ubcFlag){
        int i = alarmSetService.updateAlarmSetUbc(deviceId, ubcClass, ubcBeginValue, ubcEndValue, ubcFlag);
        if (i==1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }

    @LogAnnotation(module = "事件记录/告警设置",description = "修改线电压Uca")
    @ApiOperation("修改线电压Uca")
    @PostMapping("/updateAlarmSetUca")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "ubcClass", value = "线电压 Uca 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "ubcBeginValue", value = "线电压 Uca 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "ubcEndValue", value = "线电压 Uca 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "ubcFlag", value = "线电压 Uca 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetUca(String deviceId,Integer ucaClass,String ucaBeginValue,String ucaEndValue,Integer ucaFlag){
        int i = alarmSetService.updateAlarmSetUca(deviceId, ucaClass, ucaBeginValue, ucaEndValue, ucaFlag);
        if (i==1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }

    @LogAnnotation(module = "事件记录/告警设置",description = "相电压a")
    @ApiOperation("相电压a")
    @PostMapping("/updateAlarmSetPhaseA")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "phaseAClass", value = "相电压 a 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "phaseABeginValue", value = "相电压 a  预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "phaseAEndValue", value = "线相电压 a  预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "phaseAFlag", value = "相电压 a  1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetPhaseA(String deviceId,Integer phaseAClass,String phaseABeginValue,String phaseAEndValue,Integer phaseAFlag){
        int i  = alarmSetService.updateAlarmSetPhaseA(deviceId, phaseAClass, phaseABeginValue, phaseAEndValue, phaseAFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "相电压b")
    @ApiOperation("相电压b")
    @PostMapping("/updateAlarmSetPhaseB")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "phaseBClass", value = "相电压b 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "phaseBBeginValue", value = "相电压b 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "phaseBEndValue", value = "相电压b 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "phaseBFlag", value = "相电压b 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetPhaseB(String deviceId,Integer phaseBClass,String phaseBBeginValue,String phaseBEndValue,Integer phaseBFlag){
        int i  = alarmSetService.updateAlarmSetPhaseB(deviceId, phaseBClass, phaseBBeginValue, phaseBEndValue, phaseBFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "相电压c")
    @ApiOperation("相电压c")
    @PostMapping("/updateAlarmSetPhaseC")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "phaseCClass", value = "相电压c 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "phaseCBeginValue", value = "相电压c 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "phaseCEndValue", value = "相电压c 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "phaseCFlag", value = "相电压c 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetPhaseC(String deviceId,Integer phaseCClass,String phaseCBeginValue,String phaseCEndValue,Integer phaseCFlag){
        int i  = alarmSetService.updateAlarmSetPhaseC(deviceId, phaseCClass, phaseCBeginValue, phaseCEndValue, phaseCFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "A相电流")
    @ApiOperation("A相电流")
    @PostMapping("/updateAlarmSetElectricityA")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricityAClass", value = "A相电流 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "electricityABeginValue", value = "A相电流 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricityAEndValue", value = "A相电流 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricityAFlag", value = "A相电流 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetElectricityA(String deviceId,Integer electricityAClass,String electricityABeginValue,String electricityAEndValue,Integer electricityAFlag){
        int i  = alarmSetService.updateAlarmSetElectricityA(deviceId, electricityAClass, electricityABeginValue, electricityAEndValue, electricityAFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "B相电流")
    @ApiOperation("B相电流")
    @PostMapping("/updateAlarmSetElectricityB")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricityBClass", value = "B相电流 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "electricityBBeginValue", value = "B相电流 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricityBEndValue", value = "B相电流 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricityBFlag", value = "B相电流 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetElectricityB(String deviceId,Integer electricityBClass,String electricityBBeginValue,String electricityBEndValue,Integer electricityBFlag){
        int i  = alarmSetService.updateAlarmSetElectricityB(deviceId, electricityBClass, electricityBBeginValue, electricityBEndValue, electricityBFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "C相电流")
    @ApiOperation("C相电流")
    @PostMapping("/updateAlarmSetElectricityC")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricityCClass", value = "C相电流 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "electricityCBeginValue", value = "C相电流 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricityCEndValue", value = "C相电流 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricityCFlag", value = "C相电流 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetElectricityC(String deviceId,Integer electricityCClass,String electricityCBeginValue,String electricityCEndValue,Integer electricityCFlag){
        int i  = alarmSetService.updateAlarmSetElectricityC(deviceId, electricityCClass, electricityCBeginValue, electricityCEndValue, electricityCFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "A相有功电能")
    @ApiOperation("A相有功电能")
    @PostMapping("/updateAlarmSetElectricA")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricAClass", value = "A相有功电能 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "electricABeginValue", value = "A相有功电能 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricAEndValue", value = "A相有功电能 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricAFlag", value = "A相有功电能 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetElectricA(String deviceId,Integer electricAClass,String electricABeginValue,String electricAEndValue,Integer electricAFlag){
        int i  = alarmSetService.updateAlarmSetElectricA(deviceId, electricAClass, electricABeginValue, electricAEndValue, electricAFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "B相有功电能")
    @ApiOperation("B相有功电能")
    @PostMapping("/updateAlarmSetElectricB")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricBClass", value = "B相有功电能 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "electricBBeginValue", value = "B相有功电能 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricBEndValue", value = "B相有功电能 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricBFlag", value = "B相有功电能 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetElectricB(String deviceId,Integer electricBClass,String electricBBeginValue,String electricBEndValue,Integer electricBFlag){
        int i  = alarmSetService.updateAlarmSetElectricB(deviceId, electricBClass, electricBBeginValue, electricBEndValue, electricBFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "C相有功电能")
    @ApiOperation("C相有功电能")
    @PostMapping("/updateAlarmSetElectricC")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricCClass", value = "B相有功电能 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "electricCBeginValue", value = "B相有功电能 预设正常值从", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricCEndValue", value = "B相有功电能 预设正常值至",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "electricCFlag", value = "B相有功电能 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetElectricC(String deviceId,Integer electricCClass,String electricCBeginValue,String electricCEndValue,Integer electricCFlag){
        int i  = alarmSetService.updateAlarmSetElectricC(deviceId, electricCClass, electricCBeginValue, electricCEndValue, electricCFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }


    @LogAnnotation(module = "事件记录/告警设置",description = "DI状态")
    @ApiOperation("DI状态")
    @PostMapping("/updateAlarmSetDi")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "diClass", value = "DI状态 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "diFlag", value = "DI状态 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetDi(String deviceId, Integer diClass, Integer diFlag){
        int i  = alarmSetService.updateAlarmSetDi(deviceId, diClass, diFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }

    @LogAnnotation(module = "事件记录/告警设置",description = "通信状态")
    @ApiOperation("通信状态")
    @PostMapping("/updateAlarmSetCommunication")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",defaultValue = "05372708", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "communicationClass", value = "DI状态 1 一般 2严重 3紧急", dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "communicationFlag", value = "DI状态 1启用 2不启用", dataType = "Integer"),
    })
    public Resp updateAlarmSetCommunication(String deviceId,Integer communicationClass,Integer communicationFlag){
        int i  = alarmSetService.updateAlarmSetCommunication(deviceId, communicationClass, communicationFlag);
        if (i == 1){
            return Resp.success("修改成功");
        }
        return Resp.fail("修改失败");
    }
}
